package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.iapi.godmch.parameter.getMchIdByMchTitleBean;
import com.ymatou.iapi.godmch.service.getMchIdByMchTitleCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*根据商户名称获取商户id
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getMchIdByMchTitle{
	private static getMchIdByMchTitleBean bean;
	private static getMchIdByMchTitleCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据商户名称获取商户id");
	}

	@Before
	public void caseUp() {
		bean=new getMchIdByMchTitleBean();
		call=new getMchIdByMchTitleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdByMchTitle_001() {
		Logger.start(true,"根据商户名称获取商户id单商品-正确的mchTitle");
		try {
			//渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);

			bean.setMchTitle(editmchbean.getMchTitle());
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			Logger.verifyEquals(userId_channl, call.getMchId(), "验证返回的MchId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdByMchTitle_002() {
		Logger.start(true,"根据商户名称获取商户id单商品-不存在的mchTitle");
		try {
			bean.setMchTitle("12131231231231");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");	
			Logger.verifyEquals(null, new JsonObject().get("result"), "验证返回的MchId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdByMchTitle_003() {
		Logger.start(true,"根据商户名称获取商户id单商品-mchTitle为空");
		try {
			bean.setMchTitle(null);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatus1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证Message");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdByMchTitle_004() {
		Logger.start(true,"根据商户名称获取商户id单商品-mchTitle含特殊字符");
		try {
			bean.setMchTitle("~@#￥%……&*(+——（））（）");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");	
			Logger.verifyEquals(null, new JsonObject().get("result"), "验证返回的MchId");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdByMchTitle_005() {
		Logger.start(true,"根据商户名称获取商户id单商品-mchTitle含sql注入");
		try {
			bean.setMchTitle("update insert select");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");	
			Logger.verifyEquals(null, new JsonObject().get("result"), "验证返回的MchId");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}